'use strict';
const db = uniCloud.database();

exports.main = async (event, context) => {
    const { username } = event;
    const startTime = Date.now(); // 记录开始时间

    const res = await db.collection('users').where({
        username: username
    }).remove();

    const endTime = Date.now(); // 记录结束时间
    const executionTime = endTime - startTime; // 计算执行时间

    if (res.deleted > 0) {
        return {
            code: 200,
            msg: '用户删除成功',
            deletedCount: res.deleted, // 删除的用户数量
            executionTime: executionTime // 执行时间（毫秒）
        };
    } else {
        return {
            code: 401,
            msg: '用户不存在',
            deletedCount: 0,
            executionTime: executionTime
        };
    }
};